import string

from module_info import *
from module_scripts import *

from process_common import *
from process_operations import *

def save_scripts(variable_list,scripts):
  file = open(export_dir + "scripts.txt","w")
  file.write("scriptsfile version 1\n")
  file.write("%d\n"%len(scripts))
  for i_script in xrange(len(scripts)):
    func = scripts[i_script]
    file.write("%s \n"%(convert_to_identifier(func[0])))
    save_statement_block(file,func[1], variable_list)
    file.write("\n")
  file.close()

def save_python_header():
  file = open("./ID_scripts.py","w")
  for i_script in xrange(len(scripts)):
    file.write("script_%s = %d\n"%(convert_to_identifier(scripts[i_script][0]),i_script))
  file.write("\n\n")
  file.close()


print "Exporting scripts..."
save_python_header()
variables = load_variables(export_dir)
save_scripts(variables,scripts)
save_variables(export_dir,variables)
  
